home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #12 / Amiga Plus CD - 2002 - No. 12.iso / AmigaOS / Aplus_Dev / AP-Website / download / pgp / pgp5gui-174b.lha / PGP5GUI-Src.lha / PGP5GUI-Src / PGP5Main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-23  |  8.1 KB  |  390 lines

  1. /*
  2. ** PGP5GUI - A GUI using Magic User Interface v3.8
  3. **
  4. ** Copyright 23-JUNE-1998 by Stefan Zakarias, All Rights Reserved.
  5. **
  6. ** This source code is released as FREEWARE - Use it for whatever you like,
  7. ** as long as NO financial reward is gained by you for such usage.
  8. **
  9. ** If you use any parts of the this source code for anything, give ME credit
  10. ** wherever credit is due, please ;-)
  11. */
  12.  
  13. /*
  14. ****************************************************************************************
  15. **
  16. **    PGP5Main.c
  17. **
  18. ****************************************************************************************
  19. */
  20.  
  21. /* Libraries */
  22. #include <libraries/mui.h>
  23. #include <libraries/gadtools.h> /* for BARLABEL in MenuItem */
  24.  
  25. #include <exec/execbase.h>
  26.  
  27. /* Prototypes */
  28. #ifdef __GNUC__
  29. #include <proto/alib.h>
  30. #endif
  31.  
  32. #include <proto/muimaster.h>
  33. #include <proto/exec.h>
  34. #include <clib/alib_protos.h>
  35. #include <proto/dos.h>
  36.  
  37. #include <stdlib.h>
  38.  
  39. /* Stack size to run us with */
  40. LONG __stack=20000;
  41.  
  42. /* Include GUI stuff */
  43. #include "PGP5GUI.h"
  44.  
  45. /*
  46. ** Functions in PGP5GUI.c
  47. */
  48. extern struct ObjApp *CreateApp(void);
  49. extern void DisposeApp(struct ObjApp *);
  50.  
  51. /*
  52. ** Functions in PGP5Interface.c
  53. */
  54. extern BOOL InitASLStuff(struct ObjApp *app);
  55. extern int init_resources(void);
  56. extern void free_resources(void);
  57. extern void PGPK_list(struct ObjApp *app);
  58. extern BOOL OpenConWin(struct ObjApp *app);
  59. extern void GetWinConfigs(void);
  60. extern void EncFileOrClip(struct ObjApp *app);
  61. extern void DecFileOrClip(struct ObjApp *app);
  62. extern void SigFileOrClip(struct ObjApp *app);
  63. extern void AddKeysFileOrClip(struct ObjApp *app);
  64.  
  65. /*
  66. ** Functions in PGPEInterface.c
  67. */
  68. extern BOOL Do_Encryption(struct ObjApp *app);
  69.  
  70. /*
  71. ** Functions in PGPVInterface.c
  72. */
  73. extern void Do_Decryption(struct ObjApp *app);
  74.  
  75. /*
  76. ** Functions in PGPSInterface.c
  77. */
  78. extern void Do_Signing(struct ObjApp *app);
  79.  
  80. /*
  81. ** Functions in PGPKInterface.c
  82. */
  83. extern void Do_ADD_KEYADD(struct ObjApp *app);
  84. extern BOOL Do_EDIT_KEYCHECK(struct ObjApp *app);
  85. extern BOOL Do_EDIT_KEYDISABLE(struct ObjApp *app);
  86. extern BOOL Do_EDIT_KEYEDIT(struct ObjApp *app);
  87. extern BOOL Do_EDIT_KEYREMOVE(struct ObjApp *app);
  88. extern BOOL Do_EDIT_KEYREMSIG(struct ObjApp *app);
  89. extern BOOL Do_EDIT_KEYREMUID(struct ObjApp *app);
  90. extern BOOL Do_EDIT_KEYREVOKE(struct ObjApp *app);
  91. extern BOOL Do_EDIT_KEYREVOKESIG(struct ObjApp *app);
  92. extern BOOL Do_EDIT_KEYSIGN(struct ObjApp *app, BOOL doID);
  93. extern void Do_MISC_KEYGEN(struct ObjApp *app);
  94. extern BOOL Do_MISC_KEYEXTRACT(struct ObjApp *app);
  95. extern BOOL Do_MISC_KEYLIST(struct ObjApp *app);
  96.  
  97. /*
  98. ** Functions in FileReqPGP5.c
  99. */
  100. extern void Get_Encrypt_Name(struct ObjApp *app);
  101. extern void Get_Decrypt_Name(struct ObjApp *app);
  102. extern void Get_Sign_Name(struct ObjApp *app);
  103. extern void Get_KeysAdd_Name(struct ObjApp *app);
  104.  
  105. /* Declarations for libraries (inserted by GenCodeC) */
  106. struct Library *IntuitionBase = NULL;
  107. struct Library *MUIMasterBase = NULL;
  108. struct Library *AslBase = NULL;
  109.  
  110. int init(void);
  111. void end(void);
  112.  
  113. /*
  114. ****************************************************************************************
  115. **
  116. ** The '__main()' function.  We don't use command line or icon arguments.
  117. **
  118. ****************************************************************************************
  119. */
  120. void __stdargs __main(char *line)
  121. {
  122.     struct ObjApp *App;        /* Object */
  123.     int running;
  124.     ULONG signal;
  125.  
  126.      /* Program initialisation */
  127.     running = init();
  128.  
  129.     /* Did we init (libraries) ok? */
  130.     if (running != RETURN_OK)
  131.     {
  132.         end();
  133.         exit(RETURN_FAIL);
  134.     }
  135.  
  136.     /* Init our resources */
  137.     running = init_resources();
  138.  
  139.     /* Did we init resources ok? */
  140.     if (running != RETURN_OK)
  141.     {
  142.         PrintFault(IoErr(), "Can't init resources");
  143.         end();
  144.         exit(RETURN_FAIL);
  145.     }
  146.  
  147.     /* Get output window and ASL Requester positions and dimensions */
  148.     GetWinConfigs();
  149.  
  150.     /* Create Object */
  151.     if (!(App = CreateApp()))
  152.     {
  153.         PrintFault(IoErr(), "Can't create PGP5GUI App");
  154.         end();
  155.         exit(RETURN_FAIL);
  156.     }
  157.  
  158.     /* Open a window and connect a 'console' to it */
  159.     if (!OpenConWin(App))
  160.     {
  161.         PrintFault(IoErr(), "Can't create console");
  162.         end();
  163.         exit(RETURN_FAIL);
  164.     }
  165.  
  166.     /* Init ASL structure */
  167.     if (!InitASLStuff(App))
  168.     {
  169.         PrintFault(IoErr(), "Can't allocate ASL");
  170.         end();
  171.         exit(RETURN_FAIL);
  172.     }
  173.  
  174.     /* Get a key list */
  175.     PGPK_list(App);
  176.  
  177.     /* We're OK to continue... */
  178.     running = TRUE;
  179.  
  180.     /* The main running loop */
  181.     while (running)
  182.     {
  183.         switch (DoMethod(App->App,MUIM_Application_Input,&signal))
  184.         {
  185.             case MUIV_Application_ReturnID_Quit:
  186.                 running = FALSE;
  187.                 break;
  188.  
  189.             /* Insert your code between the "case" statement and comment "end of case ..." */
  190.             case Encrypt_DOIT:
  191.                 running = Do_Encryption(App);
  192.                 break;
  193.             /* end of case Encrypt_DOIT */
  194.  
  195.             case Decrypt_DOIT:
  196.                 Do_Decryption(App);
  197.                 break;
  198.             /* end of case Decrypt_DOIT */
  199.  
  200.             case Sign_DOIT:
  201.                 Do_Signing(App);
  202.                 break;
  203.             /* end of case Sign_DOIT */
  204.  
  205.             case ADD_KEYADD:
  206.                 Do_ADD_KEYADD(App);
  207.                 break;
  208.             /* end of case ADD_KEYADD */
  209.  
  210.             case EDIT_KEYCHECK:
  211.                 running = Do_EDIT_KEYCHECK(App);
  212.                 break;
  213.             /* end of case EDIT_KEYCHECK */
  214.  
  215.             case EDIT_KEYDISABLE:
  216.                 running = Do_EDIT_KEYDISABLE(App);
  217.                 break;
  218.             /* end of case EDIT_KEYDISABLE */
  219.  
  220.             case EDIT_KEYEDIT:
  221.                 running = Do_EDIT_KEYEDIT(App);
  222.                 break;
  223.             /* end of case EDIT_KEYEDIT */
  224.  
  225.             case EDIT_KEYREMKEY:
  226.                 running = Do_EDIT_KEYREMOVE(App);
  227.                 break;
  228.             /* end of case EDIT_KEYREMKEY */
  229.  
  230.             case EDIT_KEYREMSIG:
  231.                 running = Do_EDIT_KEYREMSIG(App);
  232.                 break;
  233.             /* end of case EDIT_KEYREMSIG */
  234.  
  235.             case EDIT_KEYREMUID:
  236.                 running = Do_EDIT_KEYREMUID(App);
  237.                 break;
  238.             /* end of case EDIT_KEYREMUID */
  239.  
  240.             case EDIT_KEYREVOKE:
  241.                 running = Do_EDIT_KEYREVOKE(App);
  242.                 break;
  243.             /* end of case EDIT_KEYREVOKE */
  244.  
  245.             case EDIT_KEYREVSIG:
  246.                 running = Do_EDIT_KEYREVOKESIG(App);
  247.                 break;
  248.             /* end of case EDIT_KEYREVSIG */
  249.  
  250.             case EDIT_KEYSIGN:
  251.                 running = Do_EDIT_KEYSIGN(App, FALSE);
  252.                 break;
  253.             /* end of case EDIT_KEYSIGN */
  254.  
  255.             case EDIT_KEYSIGNKEY:
  256.                 running = Do_EDIT_KEYSIGN(App, TRUE);
  257.                 break;
  258.             /* end of case EDIT_KEYSIGNKEY */
  259.  
  260.             case MISC_KEYGEN:
  261.                 Do_MISC_KEYGEN(App);
  262.                 break;
  263.             /* end of case MISC_KEYGEN */
  264.  
  265.             case MISC_KEYEXTRACT:
  266.                 running = Do_MISC_KEYEXTRACT(App);
  267.                 break;
  268.             /* end of case MISC_KEYEXTRACT */
  269.  
  270.             case MISC_KEYLIST:
  271.                 running = Do_MISC_KEYLIST(App);
  272.                 break;
  273.             /* end of case MISC_KEYLIST */
  274.  
  275.             case MISC_KEYLIST_UPDATE:
  276.                 PGPK_list(App);
  277.                 break;
  278.             /* end of case MISC_KEYLIST_UPDATE */
  279.  
  280.             case Pop_Enc_File:
  281.                 Get_Encrypt_Name(App);
  282.                 break;
  283.             /* end of case Pop_Enc_File */
  284.  
  285.             case Pop_Dec_File:
  286.                 Get_Decrypt_Name(App);
  287.                 break;
  288.             /* end of case Pop_Dec_File */
  289.  
  290.             case Pop_Sig_File:
  291.                 Get_Sign_Name(App);
  292.                 break;
  293.             /* end of case Pop_Sig_File */
  294.  
  295.             case Pop_Keys_AddFile:
  296.                 Get_KeysAdd_Name(App);
  297.                 break;
  298.             /* end of case Pop_Keys_AddFile */
  299.  
  300.             case Enc_FILE_CLIP:
  301.                 EncFileOrClip(App);
  302.                 break;
  303.             /* end of case Enc_FILE_CLIP */
  304.  
  305.             case Decrypt_OUTTYPE:
  306.                 DecFileOrClip(App);
  307.                 break;
  308.             /* end of case Decrypt_OUTTYPE */
  309.  
  310.             case Sig_FILE_CLIP:
  311.                 SigFileOrClip(App);
  312.                 break;
  313.             /* end of case Sig_FILE_CLIP */
  314.  
  315.             case AddKeys_FILE_CLIP:
  316.                 AddKeysFileOrClip(App);
  317.                 break;
  318.             /* end of case AddKeys_FILE_CLIP */
  319.  
  320.             /* End computing of IDCMP */
  321.  
  322.             default:
  323.                 break;
  324.         }
  325.  
  326.         if (running && signal)
  327.             Wait(signal);
  328.     }
  329.  
  330.     /* Shut down the main App */
  331.     DisposeApp(App);
  332.  
  333.     /* Free libraries */
  334.     end();
  335.  
  336.     exit(running);
  337. }
  338.  
  339. /**************************************************************************************/
  340.  
  341. /*
  342. ** Init() function
  343. */
  344. int init(void)
  345. {
  346.     int rc = RETURN_OK;
  347.  
  348.      if (!(IntuitionBase = OpenLibrary("intuition.library",37)))
  349.     {
  350.         PrintFault(IoErr(), "Can't Open Intuition Library");
  351.         rc = RETURN_FAIL;
  352.     }
  353.     else
  354.     {
  355.         if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
  356.         {
  357.             PrintFault(IoErr(), "Can't Open MUIMaster Library");
  358.             rc = RETURN_FAIL;
  359.         }
  360.         else
  361.         {
  362.             /* Open the ASL library */
  363.             if (!(AslBase = OpenLibrary("asl.library", 37L)))
  364.             {
  365.                 PrintFault(IoErr(), "Can't Open ASL Library");
  366.                 rc = RETURN_FAIL;
  367.             }
  368.         }
  369.     }
  370.  
  371.     return(rc);
  372. }
  373.  
  374. /*
  375. ** End() function
  376. */
  377. void end(void)
  378. {
  379.     free_resources();
  380.  
  381.     if (AslBase)
  382.         CloseLibrary(AslBase);
  383.  
  384.     if (MUIMasterBase)
  385.         CloseLibrary(MUIMasterBase);
  386.  
  387.     if (IntuitionBase)
  388.         CloseLibrary(IntuitionBase);
  389. }
  390.